<?php
class View_Admin_TopPage extends View_Admin_Index_Template
{
    public $oTemp;
    private $RS_CATEGORY;
    private $qty;
    public function displayTopPageIndex($oModel)
    {
    	$oModel->setData('display_menu',1);
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/top_page.html');
        $this->oTemp->assign_file('temp_message_js', PATH_TEMPLATE_ADMIN .'html/message_board_js.html');
        $this->oTemp->assign_file('temp_poup', PATH_TEMPLATE_ADMIN .'html/message_board_popup.html');
        $this->oTemp->assign('pageHeding','TOP PAGE');
    }
    
    public function displayListProduct($oModel)
    {
    	$rs=$oModel->getAllProductToday();
    	if(is_array($rs))
    	{
    		$num=0;
    		foreach($rs as $row)
    		{
    			if($row['product_explanation']!='')
    			{
    				$row['display_product_description']=URL_TEMPLATE_ADMIN . "image/tick.png";
    			}
    			else
    				$row['display_product_description']=URL_TEMPLATE_ADMIN . "image/publish_x.png";
    				
    			if($row['product_picture3']!='' || $row['product_picture2']!='' || $row['product_picture1']!='')
				{
					$row['display_product_photo']=URL_TEMPLATE_ADMIN . "image/tick.png";
				}
				else
					$row['display_product_photo']=URL_TEMPLATE_ADMIN . "image/publish_x.png";
					
				
				if($row['product_size']!="")
				{
					$row['display_size']=URL_TEMPLATE_ADMIN . "image/tick.png";
				}
				else
				{
					$row['display_size']=URL_TEMPLATE_ADMIN . "image/publish_x.png";
				}
				
				//$row['product_title'] = preview_text($row['product_title'],18);
				$this->oTemp->assign('i',$num%2);
				$num++;
							
    			$this->oTemp->assign('rowProduct',$row);
    			$this->oTemp->parse('main.rowProduct');
    			
    		}
    	}
		$this->oTemp->assign('totalItems',$oModel->getTotalItems());
		$this->oTemp->assign('totalSize',$oModel->getSizeItems());
		$this->oTemp->assign('totalPhoto',$oModel->getPhotoItems());
		$this->oTemp->assign('totalExplaination',$oModel->getExplainationItems());
		$this->oTemp->assign('totalTitle',$oModel->getTitleItems());
		$this->oTemp->assign('totalDone',$oModel->getDoneItems());
    }
    
    public function displayStaticCategory($oModel)
    {
    	$rs=$oModel->getListGroupCategory();
    	if(is_array($rs))
    	{
    		$level=0;
    		$num=0;
    		foreach($rs as $row)
    		{   
    			$this->qty=0;
    			$arr=explode(' ',$row['group_child']);
    			if(is_array($arr))
    			{
    				foreach($arr as $arr_row)
    				{
    					$this->getAllChild($oModel,trim($arr_row),$level);
    				}
    			}
    			$row['product_category_qty']=$this->qty;
    			$this->oTemp->assign('i',$num%2);
				$num++;
    			$this->oTemp->assign('rowCategory', $row);
                $this->oTemp->parse('main.rowCategory');
                
                //$this->getAllChild($oModel,$row['product_category_id'],$level);
    		}
    	}
    }
    
    public function getAllChild($oModel,$parent_id,$level)
    {
    	$rs=$oModel->getListStaticCategoryChild($parent_id);
    		if(is_array($rs))
    		{
    			//$level++;
    			foreach($rs as $row)
    			{
    				//$row['product_category_name']=str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",$level).$row['product_category_name'];
    				//$row['level']=$level;
                	if($row['product_category_yahoo_id']!=0)
                	{
                		$row['product_category_qty']=$oModel->getQtyProductOfCategory($row['product_category_yahoo_id']);
                		$this->qty+=$row['product_category_qty'];
                		//$this->oTemp->assign('rowCategory', $row);
                		//$this->oTemp->parse('main.rowCategory');
                	}
                	else
                	{
					$this->getAllChild($oModel,$row['product_category_id'],$level);
					}
    			}
    	}
    }
    
    /**
     * MESSAGE BOARD
     */
     public function displayListMessageBoard($oModel)
     {
     	$rs=$oModel->getListMessage();
     	if(is_array($rs))
     	{
     		$num=0;
     		foreach($rs as $row)
     		{
     			$this->oTemp->assign('i',$num%2);
				$num++;
				$user_to=$oModel->getInfoUserById($row['message_to']);
				$row['display_message_to']=$user_to['user_to'];
     			$this->oTemp->assign('rowMessageBoard', $row);
                $this->oTemp->parse('main.rowMessageBoard');
     		}
     	}
     }
}